/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.siseventos.view.util;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;

/**
 *
 * @author marcosnatanpacheco
 */
public class MessageHelper {
    // Campos estáticos

    private static FacesMessage msg;
    private static Severity s;
    // Serviço

    public static void showGlobalMessage(String message, Severity level) {
        s = (level != null) ? level : FacesMessage.SEVERITY_INFO;
        getMsg().setSummary(message);
        getMsg().setSeverity(s);
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    
    public static  void showMessageForControl(String control, String message, Severity level){
        s = (level != null) ? level : FacesMessage.SEVERITY_INFO;
        getMsg().setSummary(message);
        getMsg().setSeverity(s);
        FacesContext.getCurrentInstance().addMessage(control, msg);
    }
    
    public void clearMesssages(FacesContext contexto){

    }
    // Métodos estáticos privados
    private static FacesMessage getMsg() {
        if (msg == null) {
            msg = new FacesMessage();
        }
        return msg;
    }
}
